/**
 * Ts 中的 泛型工具函数
 *    参考链接：https://juejin.cn/post/7084241167696527396
 *
 *    1. ReturnType<函数类型> => 函数类型的返回值的类型
 *
 *    2. Required<类型>      => 将类型中每一项key都变成必须的类型
 *
 *    3. Partial<类型>       => 将传入类型中的每一项都添加为可选
 *
 *    4.
 */

interface IPerson {
  name: string;
  age: number;
  gender?: number;
}

const p1: IPerson = {
  name: "张三",
  age: 18,
};

// interface IPerson2 {
//   name: string;
//   age: number;
//   gender: number;
// }

type IPerson2 = Required<IPerson>;

const p2: IPerson2 = {
  name: "李四",
  age: 18,
  gender: 1,
};

type IPerson3 = Partial<IPerson>;

type IName = IPerson["name"]; // 将 IPerson 这个类型中 key 值为 name 的类型给取出来

type IPerson4 = Readonly<IPerson>;

const p4: IPerson4 = {
  name: "张三",
  age: 18,
};

// p4.name = "";

// Record

interface ICoffee {
  name: string;
  size: "BIG" | "MIDDLE" | "SMALL";
}

// interface IObj {
//   a: ICoffee,
//   b: ICoffee
// }

type IObj = Record<"a" | "b", ICoffee>;

// 现有需要由一个对象的，对象中有 a 属性 和 b 属性，两个属性值的类型，要满足 ICoffee
const obj = {
  a: {
    name: "美式",
    size: "BIG",
  },
  b: {
    name: "拿铁",
    size: "SMALL",
  },
};

const obj1: IObj = {
  a: {
    name: "美式",
    size: "BIG",
  },
  b: {
    name: "拿铁",
    size: "SMALL",
  },
};

// Pick

interface User {
  name: string;
  age: number;
  password: string;
}

type xx = Pick<User, "name" | "age">;

// Omit
type yy = Omit<User, "password">;
